package cn.edu.njtc.controller;

import cn.edu.njtc.common.R;
import cn.edu.njtc.entity.pojo.Transaction;
import cn.edu.njtc.service.TransactionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/transaction")
@Tag(name = "充值缴费管理接口")
public class TransactionController {

    @Autowired
    private TransactionService transactionService;

    @Operation(summary = "用户充值")
    @PostMapping("/recharge")
    public R<Transaction> recharge(
            @Parameter(description = "用户ID") @RequestParam Integer userId,
            @Parameter(description = "充值金额") @RequestParam BigDecimal amount) {
        Transaction transaction = transactionService.recharge(userId, amount);
        return R.ok(transaction);
    }
    @Operation(summary = "用户消费")
    @PostMapping("/consume")
    public R<Transaction> consume(
            @Parameter(description = "用户ID") @RequestParam Integer userId,
            @Parameter(description = "消费金额") @RequestParam BigDecimal amount,
            @Parameter(description = "消费备注") @RequestParam String notes) {
        Transaction transaction = transactionService.consume(userId, amount, notes);
        return R.ok(transaction);
    }
    @Operation(summary = "根据用户ID查询交易记录")
    @GetMapping("/list/{userId}")
    public R<List<Transaction>> getTransactionsByUserId(
            @Parameter(description = "用户ID") @PathVariable Integer userId) {
        List<Transaction> transactions = transactionService.getTransactionsByUserId(userId);
        return R.ok(transactions);
    }
}